%--------------------------------------------------------------------------
%   rt toolbox
%   author:qwe14789cn@gmail.com
%   https://github.com/qwe14789cn/radar_tools
%--------------------------------------------------------------------------
%   rt.vpp2dbm(Vpp,R)
%--------------------------------------------------------------------------
%   Description:
%   volt to dbm
%--------------------------------------------------------------------------
%   input:
%           Vpp                 signal peak to peak volt
%           R                   resistance(default=50)
%   output:
%           dbm
%--------------------------------------------------------------------------
%   Examples:
%   rt.vpp2dbm(1)
%   ans =3.9794
%   rt.vpp2dbm(1,1e6)
%   ans = -39.0309
%--------------------------------------------------------------------------
function dBm = vpp2dbm(Vpp,R)
if nargin==1
    R=50;
end
dBm = 20*log10(Vpp/2)-10*log10(2*R)+30;
end